﻿using DrCarDrive.DBService;
using DrCarDrive.Util;
using DrCarDrive.Wpf.WpfWindow;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DrCarDrive.Wpf.WpfPage
{
    /// <summary>
    /// Interaction logic for FuelTopUp.xaml
    /// </summary>
    public partial class IssueMedicine : Page
    {
        private static IssueMedicine instance;
        private MedicineService medicineService;
        public IssueMedicine()
        {
            InitializeComponent();
        }

        public static object Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new IssueMedicine();
                }

                return instance;
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            txtDosage.Text = "";
            txtRemark.Text = "";
            txtUnit.Text = "";
        }

        private void btnSaveMedicine_Click(object sender, RoutedEventArgs e)
        {
            if (validate() == true)
            {
                tbl_issue_medicine medicine = new tbl_issue_medicine();
                medicine.ID = GUIDGenerator.medicineKey();
                medicine.DOSAGE = Double.Parse(txtDosage.Text);
                medicine.UNIT = txtUnit.Text;
                medicine.FKY_PLACE = SessionData.place.ID;

                medicineService = new MedicineService();
                //MessageBox.Show();
                int status = medicineService.save(medicine);
                if (status > 0)
                {
                   // SessionData.drive = drive;
                    MainWindow.Instance.ContentFrame.Content = DashboardPage.Instance;
                }
            }
            else
            {
                MSGWindow errorWindow = new MSGWindow(Messages.TTL_FILL_REQUIRED, Messages.MSG_FILL_REQUIRED_INFORMATION);
                errorWindow.Show();
            }



        }

        private Boolean validate()
        {
            if (txtDosage.Text == "" || txtUnit.Text == "" )
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        public static void destroy()
        {
            instance = null;
        }
    }
}
